home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-11 | 24.0 KB | 877 lines | [TEXT/MPS ] |
- /*
- File: Palette.cpp
-
- Contains: Palette Classes Implementation
-
- Written by: Dave Stafford
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- */
-
- // -- Compiler/Preprocessor Switches --
-
- #ifndef _COMPILERDEFS_
- #include "CompDefs.h"
- #endif
-
- // -- DrawEditor Includes --
-
- #ifndef _DRAWEDITORGLOBALS_
- #include "DrawEditorGlobals.h"
- #endif
-
- #ifndef _DRAWEDITORCONSTANTS_
- #include "DrawEditorConstants.h"
- #endif
-
- #ifndef _PALETTE_
- #include "Palette.h"
- #endif
-
- #ifndef _DRAWEDITOR_
- #include "DrawEditor.h"
- #endif
-
- #ifndef _DRAWEDITORUTILS_
- #include "DrawEditorUtils.h"
- #endif
-
- // -- OpenDoc Includes --
-
- #ifndef SOM_ODBinding_xh
- #include <ODBindng.xh>
- #endif
-
- #ifndef SOM_ODTranslation_xh
- #include <Translt.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODInfo_xh
- #include <Info.xh>
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _ODUTILS_
- #include "ODUtils.h"
- #endif
-
- #ifndef _USERSRCM_
- #include "UseRsrcM.h" // allow access to our library's resource fork
- #endif
-
- #ifndef _ODMEMORY_
- #include "ODMemory.h" // ODDisposePtr
- #endif
-
- #ifndef _FOCUSLIB_
- #include <FocusLib.h>
- #endif
-
- // -- Toolbox Includes --
-
- #ifndef mathRoutinesIncludes
- #include <math routines.h>
- #endif
-
- #ifndef __MEMORY__
- #include <memory.h>
- #endif
-
-
-
- // **************************** Need to improve Handling of Failure **********************
-
- //----------------------------------------------------------------------------------------
- // FW_CColor::operator=
- //----------------------------------------------------------------------------------------
-
- CRGBColor& CRGBColor::operator=(const RGBColor& rgb)
- {
- red = rgb.red;
- green = rgb.green;
- blue = rgb.blue;
- return (*this);
- }
-
-
- //----------------------------------------------------------------------------------------
- // CPalette::CPalette
- //----------------------------------------------------------------------------------------
-
- CPalette::CPalette(DrawEditor* part)
- {
- fSelectedPaletteItem = 0;
- fDrawEditor = part;
- fPresentation = kODNULL;
- fODWindowID = kODNULLID;
- }
-
-
- //----------------------------------------------------------------------------------------
- // CPalette::~CPalette
- //----------------------------------------------------------------------------------------
-
- CPalette::~CPalette()
- {
- }
-
-
- //----------------------------------------------------------------------------------------
- // CPalette::GetSelectedPaletteItem
- //----------------------------------------------------------------------------------------
-
- ODSShort CPalette::GetSelectedPaletteItem() const
- {
- return fSelectedPaletteItem;
- }
-
- //----------------------------------------------------------------------------------------
- // CPalette::SetSelectedPaletteItem
- //----------------------------------------------------------------------------------------
-
- void CPalette::SetSelectedPaletteItem(ODSShort paletteItem)
- {
- fSelectedPaletteItem = paletteItem;
- }
-
-
- //----------------------------------------------------------------------------------------
- // CPalette::GetPresentation
- //----------------------------------------------------------------------------------------
-
- ODTypeToken CPalette::GetPresentation() const
- {
- return fPresentation;
- }
-
-
- //----------------------------------------------------------------------------------------
- // CPalette::SetPresentation
- //----------------------------------------------------------------------------------------
-
- void CPalette::SetPresentation(ODTypeToken presentation)
- {
- fPresentation = presentation;
- }
-
-
- //----------------------------------------------------------------------------------------
- // CPalette::GetPaletteWindow
- //----------------------------------------------------------------------------------------
-
- ODWindow* CPalette::GetPaletteWindow(Environment* ev)
- {
- return fDrawEditor->GetSession(ev)->GetWindowState(ev)->AcquireWindow(ev, fODWindowID);
- }
-
-
- //----------------------------------------------------------------------------------------
- // CPalette::CreatePalette
- //----------------------------------------------------------------------------------------
-
- void CPalette::CreatePalette(Environment* ev)
- {
-
- ODSession* session = fDrawEditor->GetSession(ev);
- ODWindowState* windowState = session->GetWindowState(ev);
-
- // Setup Name
- Str255 windowTitle = "\p";
-
- // Cache tokenized form of presentation
- TokenizePalettePresentation(ev, session);
- fPresentation = GetPresentation();
-
- Rect windowRect;
-
- GetPaletteRect(&windowRect);
-
- // Using the name and the calculated rectangle, create a new window.
- // Note: that we are allocating the window record in temp mem using
- // the OpenDoc memory mgr. This helps reduce app heap usage.
- ODPlatformWindow platformWindow = kODNULL;
- platformWindow = ::NewCWindow((Ptr)::ODNewPtr(sizeof(WindowRecord)),
- &windowRect,
- windowTitle,
- kODFalse,
- floatProc,
- (WindowPtr)-1L,
- true,
- kODNULL);
-
- // If NewCWindow returned NULL it is possible that we are running on a pre 7.5
- // system that does not support the new floatWindow window proc so,
- // use our own..
- if (platformWindow==kODNULL)
- {
- platformWindow = ::NewCWindow((Ptr)::ODNewPtr(sizeof(WindowRecord)),
- &windowRect,
- windowTitle,
- kODFalse,
- kFloatWindowDefID * 16,
- (WindowPtr)-1L,
- true,
- kODNULL);
-
- // Release the window proc that was loaded for this window
- // Then substitute our global one
- Handle temp = ((WindowPeek)platformWindow)->windowDefProc;
- ((WindowPeek)platformWindow)->windowDefProc = gGlobals->fFloatWindowProc;
- ::ReleaseResource(temp);
- }
-
-
- // ----- Create and return the OD window
- ODWindow* window = windowState->RegisterWindow(ev,
- platformWindow,
- kODNonPersistentFrameObject,
- kODFalse, // root window
- kODFalse, // On the Mac we handle the resizing ourself
- kODTrue, // Is a floating window
- false, // shouldSave
- kODFalse, // Allow OpenDoc to dispose this window?
- fDrawEditor->GetODPart(),
- session->Tokenize(ev, kODViewAsFrame),
- fPresentation,
- kODNULL);
- THROW_IF_NULL(window);
-
- fODWindowID = window->GetID(ev);
- ODReleaseObject(ev, window);
-
- }
-
- //----------------------------------------------------------------------------------------
- // CPalette::ClosePalette
- //----------------------------------------------------------------------------------------
- void CPalette::ClosePalette(Environment* ev)
- {
- // Get the window reference for the palette, if there is one
- ODWindow* window = this->GetPaletteWindow(ev);
-
- if (window)
- {
- // Close and Release the window
- ODReleaseObject(ev, window);
- window->CloseAndRemove(ev);
- fODWindowID = kODNULLID;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CPalette::IsShown
- //----------------------------------------------------------------------------------------
- ODBoolean CPalette::IsShown(Environment* ev)
- {
- ODBoolean shown = kODFalse;
-
- // Get the window reference for the palette, if there is one
- ODWindow* window = this->GetPaletteWindow(ev);
-
- if (window==kODNULL)
- {
- return kODFalse;
- }
-
- shown = window->IsShown(ev);
-
- // Release the acquired window
- ODReleaseObject(ev, window);
-
- return shown;
- }
-
- //----------------------------------------------------------------------------------------
- // CPalette::ShowPalette
- //----------------------------------------------------------------------------------------
-
- void CPalette::ShowPalette(Environment* ev, ODBoolean show)
- {
- // Get the window reference for the palette, if there is one
- ODWindow* window = this->GetPaletteWindow(ev);
-
- if (show&&!this->IsShown(ev))
- {
- if (window==kODNULL)
- {
- CreatePalette(ev);
-
- window = this->GetPaletteWindow(ev);
-
- // If we don't have a window at this point then something is wrong
- THROW_IF_NULL(window);
- window->Open(ev);
- }
-
- window->Show(ev);
- }
- else
- if (!show&&this->IsShown(ev))
- {
- if (window!=kODNULL)
- window->Hide(ev);
- }
-
- // Release the acquired window
- ODReleaseObject(ev, window);
- }
-
- //==============================================================================
- // CColorPalette
- //==============================================================================
-
- const short CColorPalette::kColorPaletteHeight = 170;
- const short CColorPalette::kColorPaletteWidth = 170;
- const short CColorPalette::kColorSwatchAreaOffset = 4;
- const short CColorPalette::kColorSwatchSize = 11;
-
- //----------------------------------------------------------------------------------------
- // CColorPalette::CColorPalette
- //----------------------------------------------------------------------------------------
-
- CColorPalette::CColorPalette(DrawEditor* part) : CPalette(part),
- fColorTable(NULL)
- {
- fColorTable = ::GetCTable(72);
- fNumbersOfColors = 256;
- fSavedInvalidRect.top = ff(kColorSwatchAreaOffset);
- fSavedInvalidRect.left = ff(kColorSwatchAreaOffset);
- fSavedInvalidRect.bottom = ff(kColorSwatchAreaOffset + kColorSwatchSize);
- fSavedInvalidRect.right = ff(kColorSwatchAreaOffset + kColorSwatchSize);
- }
-
-
- //----------------------------------------------------------------------------------------
- // CColorPalette::~CColorPalette
- //----------------------------------------------------------------------------------------
-
- CColorPalette::~CColorPalette()
- {
- if (fColorTable)
- ::DisposeCTable(fColorTable);
- }
-
- //----------------------------------------------------------------------------------------
- // CColorPalette::GetColor
- //----------------------------------------------------------------------------------------
-
- void CColorPalette::GetColor(short colorIndex, CRGBColor* color) const
- {
- *color = ((*fColorTable)->ctTable[colorIndex].rgb);
- }
-
- //----------------------------------------------------------------------------------------
- // CColorPalette::NumberOfColors
- //----------------------------------------------------------------------------------------
-
- ODSShort CColorPalette::NumberOfColors() const
- {
- return fNumbersOfColors;
- }
-
- //----------------------------------------------------------------------------------------
- // CColorPalette::GetPaletteRect
- //----------------------------------------------------------------------------------------
-
- void CColorPalette::GetPaletteRect(Rect* r)
- {
- SetRect(r, 80, 80, 80 + kColorPaletteWidth, 80 + kColorPaletteHeight);
- }
-
- //----------------------------------------------------------------------------------------
- // CColorPalette::TokenizePalettePresentation
- //----------------------------------------------------------------------------------------
-
- void CColorPalette::TokenizePalettePresentation(Environment* ev, ODSession* session)
- {
- SetPresentation(session->Tokenize(ev, kColorPalettePresentation));
- }
-
- //----------------------------------------------------------------------------------------
- // CColorPalette::Draw
- //----------------------------------------------------------------------------------------
-
- void CColorPalette::Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape)
- {
- ODSShort x;
- Rect box, colorbox;
- CRGBColor saveColor, swatchColor;
-
- const short kPenWidth = 1;
-
- CFocus using(ev, facet);
-
- // Get frame bounds for drawing.
- ODShape* frameShape = facet->GetFrame(ev)->AcquireFrameShape(ev, kODNULL);
- RgnHandle frameRgn = (frameShape->GetQDRegion(ev));
- Rect frameRect = (**frameRgn).rgnBBox;
- ODReleaseObject(ev, frameShape);
-
- SetRect(&box, kColorSwatchAreaOffset, kColorSwatchAreaOffset, kColorSwatchSize + kColorSwatchAreaOffset, kColorSwatchSize + kColorSwatchAreaOffset);
-
- for ( x = 0; x < fNumbersOfColors; x++ )
- {
- Point boxCorner = {box.bottom,box.right};
- if (!PtInRgn(boxCorner, frameRgn))
- {
- OffsetRect(&box, 0, kColorSwatchSize - kPenWidth );
- box.left = kColorSwatchAreaOffset;
- box.right = kColorSwatchSize + kColorSwatchAreaOffset;
- }
-
- FrameRect(&box);
-
- colorbox = box;
-
- GetForeColor((RGBColor*)&saveColor);
- GetColor(x, &swatchColor);
- RGBForeColor((RGBColor*)&swatchColor);
-
- InsetRect(&colorbox, kPenWidth, kPenWidth);
- PaintRect(&colorbox);
-
- // Hilight the selected item
- if (x == GetSelectedPaletteItem())
- {
- CRGBColor black(0,0,0);
- RGBForeColor((RGBColor*)&black);
-
- PenState savePen;
- GetPenState(&savePen);
- PenSize(2, 2);
- FrameRect(&box);
- SetPenState(&savePen);
- }
-
- RGBForeColor((RGBColor*)&saveColor);
-
- OffsetRect(&box, kColorSwatchSize - kPenWidth, 0);
- }
-
- }
-
- //----------------------------------------------------------------------------------------
- // CColorPalette::DoMouseDownInPalette
- //----------------------------------------------------------------------------------------
-
- ODBoolean CColorPalette::DoMouseDownInPalette(Environment* ev,
- ODFrame* frame,
- Point where,
- ODSShort* chosenItem,
- ODBoolean changePalette)
- {
- ODSShort savedPaletteItem = GetSelectedPaletteItem();
- ODSShort newPaletteItem;
- Rect mouseDownRect;
- ODSShort rowSize = ( kColorPaletteWidth - kColorSwatchAreaOffset ) / kColorSwatchSize +1;
-
- // Eliminate the border area
- ODSShort horz = where.h - kColorSwatchAreaOffset;
- ODSShort vert = where.v - kColorSwatchAreaOffset;
-
- // Initialize chosenItem return parameter
- if (chosenItem)
- *chosenItem = 0;
-
- // Do nothing if a grid line was clicked in
- if ( (!horz % kColorSwatchSize)||(!horz % kColorSwatchSize))
- return kODFalse;
-
- // eliminate the pen lines
- horz = horz - horz / kColorSwatchSize;
- vert = vert - vert / kColorSwatchSize;
-
- // Find the row / column
- ODSShort column = horz / ( kColorSwatchSize - 2 );
- ODSShort row = vert / ( kColorSwatchSize - 2 );
-
- // New selected palette item
- newPaletteItem = row * rowSize + column;
-
- // Define the clicked rectangle
- SetRect( &mouseDownRect, column * kColorSwatchSize,
- row * kColorSwatchSize,
- (column + 1) * kColorSwatchSize,
- (row + 1) * kColorSwatchSize );
-
- OffsetRect( &mouseDownRect, kColorSwatchAreaOffset - column, kColorSwatchAreaOffset - row );
-
- // Set the chosen color parameter
- if (chosenItem)
- *chosenItem = newPaletteItem;
-
- if (newPaletteItem==savedPaletteItem)
- return kODFalse;
-
- ODRect invalidRect;
-
- // Only make changes to the palette if changePalette parameter is true
- if (changePalette == kODTrue)
- {
- // Invalidate the old color swatch to force redrawing of the
- // tool highlighting
-
- ODShape* invalidShape = frame->CreateShape(ev);
- invalidShape->SetRectangle(ev, &fSavedInvalidRect);
-
- frame->Invalidate(ev, invalidShape, kODNULL); // Pass NULL for the bias Canvas
-
- // Release the ref counted object
- ODReleaseObject(ev, invalidShape);
- invalidShape = kODNULL;
-
- // Invalidate the new color swatch to force redrawing of the
- // tool highlighting
- invalidRect.top = ff(mouseDownRect.top);
- invalidRect.left = ff(mouseDownRect.left);
- invalidRect.bottom = ff(mouseDownRect.bottom);
- invalidRect.right = ff(mouseDownRect.right);
-
- invalidShape = frame->CreateShape(ev);
- invalidShape->SetRectangle(ev, &invalidRect);
-
- frame->Invalidate(ev, invalidShape, kODNULL); // Pass NULL for the bias Canvas
-
- // Release the ref counted object
- ODReleaseObject(ev, invalidShape);
- invalidShape = kODNULL;
-
- // Set current item
- SetSelectedPaletteItem(newPaletteItem);
-
- // Save the new rect to be invalidated for the next change
- fSavedInvalidRect = invalidRect;
- }
-
- return kODTrue;
- }
-
- //==============================================================================
- // CToolPalette
- //==============================================================================
-
- const short CToolPalette::kToolPaletteHeight = 80;
- const short CToolPalette::kToolPaletteWidth = 54;
- const short CToolPalette::kPaletteBasePictureID = kBaseResourceID;
- const short CToolPalette::kToolCount = 7;
- const short CToolPalette::kToolSize = 26;
- const short CToolPalette::kToolOffset = 2;
-
- //----------------------------------------------------------------------------------------
- // CToolPalette::CToolPalette
- //----------------------------------------------------------------------------------------
-
- CToolPalette::CToolPalette(DrawEditor* part) : CPalette(part)
- {
- fToolPicts = kODNULL;
- fTextToolActive = kODFalse;
-
- // Default to selection tool
- SetSelectedPaletteItem(kSelectionTool);
- }
-
-
- //----------------------------------------------------------------------------------------
- // CToolPalette::~CToolPalette
- //----------------------------------------------------------------------------------------
-
- CToolPalette::~CToolPalette()
- {
- if (fToolPicts)
- {
- for ( ODSShort index = 0; index < ( kToolCount + 1 ); index ++)
- {
- PicHandle pict = fToolPicts[index];
- if (pict)
- ::ODDeletePicture(pict);
- }
- ::ODDisposePtr(fToolPicts);
- fToolPicts = kODNULL;
- }
- }
-
-
-
- //----------------------------------------------------------------------------------------
- // CToolPalette::AdjustTextTool
- //----------------------------------------------------------------------------------------
-
- void CToolPalette::AdjustTextTool(Environment* ev)
- {
- // Check to see if there is actually a text editor available
- ODSession* session = fDrawEditor->GetSession(ev);
- ODBoolean editorIsAvailable;
-
- TRY
- ODEditor editorID = session->GetBinding(ev)->
- ChooseEditorForPart(ev, kODNULL, gGlobals->fCurrentTextPartKind);
-
- editorIsAvailable = strcmp(editorID, kODBlackBoxHandlerOfLastResort);
- CATCH_ALL
- editorIsAvailable = kODFalse;
- ENDTRY
-
- // If we concur with reality, then return
- if (editorIsAvailable == fTextToolActive)
- return;
-
- // Adjust our flag
- fTextToolActive = editorIsAvailable;
-
- // Invalidate tool
- this->ActivateTool(ev, kTextTool);
-
- }
- //----------------------------------------------------------------------------------------
- // CToolPalette::CreatePalette
- //----------------------------------------------------------------------------------------
-
- void CToolPalette::CreatePalette(Environment* ev)
- {
- ODSLong savedRefNum;
-
-
- // Get and Detach the resource before we
- // release the resource file
-
- savedRefNum = BeginUsingLibraryResources();
-
- // Load the main palette picture and the six tool picts
- fToolPicts = (PicHandle*) ::ODNewPtrClear(sizeof(PicHandle) * (kToolCount + 1));
- THROW_IF_NULL(fToolPicts);
-
- for ( ODSShort index = 0; index < kToolCount + 1; index ++)
- {
- PicHandle pict = ::ODLoadPicture(kPaletteBasePictureID+index);
-
- if (pict==kODNULL)
- {
- // There is a bug in ResError, when resources are not found,
- // which may cause noErr to be returned. If that is the case,
- // we throw resNotFound.
- THROW_IF_ERROR((ODError)ResError());
- THROW(resNotFound);
- }
- fToolPicts[index] = pict;
- }
-
- EndUsingLibraryResources(savedRefNum);
-
- // Set the text tool flag
- this->AdjustTextTool(ev);
-
- SetSelectedPaletteItem(1);
-
- CPalette::CreatePalette(ev);
- }
-
-
- //----------------------------------------------------------------------------------------
- // CToolPalette::GetPaletteRect
- //----------------------------------------------------------------------------------------
-
- void CToolPalette::GetPaletteRect(Rect* r)
- {
- SetRect(r, 460, 80, 460 + kToolPaletteWidth, 80 + kToolPaletteHeight);
- }
-
- //----------------------------------------------------------------------------------------
- // CToolPalette::GetToolRect
- //----------------------------------------------------------------------------------------
-
- void CToolPalette::GetToolRect(short tool, Rect* rect)
- {
- // Find the column & row
- ODSShort col = !(tool % 2);
- ODSShort row = tool / 2 - ( tool + 1) % 2;
-
- SetRect( rect, col * kToolSize + kToolOffset - col,
- row * kToolSize + kToolOffset - row,
- col * kToolSize + kToolSize + kToolOffset - col,
- row * kToolSize + kToolSize + kToolOffset - row );
- }
-
- //----------------------------------------------------------------------------------------
- // CToolPalette::TokenizePalettePresentation
- //----------------------------------------------------------------------------------------
-
- void CToolPalette::TokenizePalettePresentation(Environment* ev, ODSession* session)
- {
- SetPresentation(session->Tokenize(ev, kToolPalettePresentation));
- }
-
- //----------------------------------------------------------------------------------------
- // CToolPalette::Draw
- //----------------------------------------------------------------------------------------
-
- void CToolPalette::Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape)
- {
- CFocus using(ev, facet);
-
- // Draw the main tool picture
- Rect bounds = (**(PicHandle) fToolPicts[0]).picFrame;
- OffsetRect(&bounds, -bounds.left, -bounds.top);
- DrawPicture((PicHandle) fToolPicts[0], &bounds);
-
- // Highlight the active tool
- ODSShort selectedTool = GetSelectedPaletteItem();
- GetToolRect( selectedTool, &bounds );
-
- // Draw the inverted tool picture for the selected tool
- DrawPicture((PicHandle) fToolPicts[selectedTool], &bounds);
-
- // If the text part is not available then display the
- // inactive text tool button
- if (!fTextToolActive)
- {
- // Draw the disabled text tool pict over the active one.
- GetToolRect( kTextTool, &bounds );
- DrawPicture((PicHandle) fToolPicts[kInactiveTextTool], &bounds);
- }
-
- }
-
-
- //----------------------------------------------------------------------------------------
- // CToolPalette::InvalidateTool
- //----------------------------------------------------------------------------------------
-
- void CToolPalette::InvalidateTool(Environment* ev, ODSShort whichTool)
- {
- Rect whichToolRect;
-
- // Window & Frame
- ODWindow* tWindow = this->GetPaletteWindow(ev);
- THROW_IF_NULL(tWindow);
-
- ODFrame* paletteFrame = tWindow->GetRootFrame(ev);
-
- // Get the picts bounds
- GetToolRect( whichTool, &whichToolRect );
-
- // Convert to an ODRect and call frame::invalidate
- ODRect invalidRect(whichToolRect);
- ODShape* invalidShape = paletteFrame->CreateShape(ev);
- invalidShape->SetRectangle(ev, &invalidRect);
- paletteFrame->Invalidate(ev, invalidShape, kODNULL);
-
- // Release acquired geometry
- ODReleaseObject(ev, invalidShape);
-
- // Release acquired window
- ODReleaseObject(ev, tWindow);
- }
-
- //----------------------------------------------------------------------------------------
- // CToolPalette::ActivateTool
- //----------------------------------------------------------------------------------------
-
- void CToolPalette::ActivateTool(Environment* ev, ODSShort whichTool)
- {
- // If the palette isn't shown then we can't operate on the window
- // because it hasn't yet been loaded.
- if (!this->IsShown(ev))
- return;
-
- // If they want to activate the text tool and it isn't available then bail.
- if (!fTextToolActive && whichTool == kTextTool)
- return;
-
- // Invalidate the old tool
- this->InvalidateTool(ev, this->GetSelectedPaletteItem());
-
- // Invalidate the new tool
- this->InvalidateTool(ev, whichTool);
-
- // Change the current tool
- SetSelectedPaletteItem(whichTool);
- }
-
-
- //----------------------------------------------------------------------------------------
- // CToolPalette::DoMouseDownInPalette
- //----------------------------------------------------------------------------------------
-
- ODBoolean CToolPalette::DoMouseDownInPalette(Environment* ev,
- ODFrame* frame,
- Point where,
- ODSShort* chosenItem,
- ODBoolean changePalette)
- {
- ODSShort savedPaletteItem = GetSelectedPaletteItem();
-
- for (ODSShort i = 1; i <= kToolCount; i++)
- {
-
- Rect checkBounds;
- ODSShort column = i % 2;
- ODSShort row = i / 2 - i % 2;
-
- GetToolRect( i, &checkBounds );
-
- // Set the chosenItem return parameter
- if (chosenItem)
- *chosenItem = i;
-
- if (changePalette == kODTrue)
- {
- if ( PtInRect(where, &checkBounds ))
- {
- if (i==savedPaletteItem)
- return kODFalse;
-
- // If the user is clicking on a text tool, check to see if we have one.
- // This also helps when the user was missing a text editor, then got one
- // and needs the palette to update.
- if (i==kTextTool)
- {
- // Set the text tool flag
- this->AdjustTextTool(ev);
- }
-
- // Change the palette
- this->ActivateTool(ev, i);
-
- return kODTrue;
- }
- }
- }
-
- return kODFalse;
- }
-
-
-